﻿package  
{
	
	/**
	 * ...
	 * @author Ben Humberston
	 */
	public class Vector2 
	{
		public var x:Number;
		public var y:Number;
		
		public function Vector2(x:Number = 0, y:Number = 0) 
		{
			this.x = x; this.y = y;
		}
		
		public function normalize():void {
			if (x == 0 && y == 0) {
				trace("Tried to normalize a 0 vector...");
				return;
			}
			var len:Number = Math.sqrt(lenSqrd());
			x /= len;
			y /= len;
		}
		
		public function lenSqrd():Number {
			return x * x + y * y;
		}
		
		public function len():Number {
			return Math.sqrt(lenSqrd());
		}
		
		public function scale(scalar:Number):void {
			x *= scalar; 
			y *= scalar;
		}
		
		public function toString():String {
			var displayX:String = x.toFixed(5);
			var displayY:String = y.toFixed(5);
			return displayX + ", " + displayY;
		}
		
	}
	
}